﻿using JamesZhao.Engine.GameObjects;
using JamesZhao.Engine.Graphics;
using SlimMath;

namespace JamesZhao.Engine.GameComponents
{
    public class CameraComponent : GameComponent
    {
        private Camera _camera;

        public CameraComponent(GameObject owner) : base(owner)
        {
            Transform.LocalRotation =
                Quaternion.RotationYawPitchRoll(MathExtended.DegreesToRadians(0), 0, 0);
        }

        public float Far
        {
            get { return _camera.Lens.Far; }
            set { _camera.Lens.Far = value; }
        }

        public float Near
        {
            get { return _camera.Lens.Near; }
            set { _camera.Lens.Near = value; }
        }

        public float AspectRatio
        {
            get { return _camera.Lens.AspectRatio; }
            set { _camera.Lens.AspectRatio = value; }
        }

        public float FieldOfView
        {
            get { return _camera.Lens.FieldOfView; }
            set { _camera.Lens.FieldOfView = value; }
        }

        public override void Initialize()
        {
            base.Initialize();
            _camera = new Camera();
            Engine.GraphicsManager.MainViewport.Camera = _camera;

            Far = 200;
            Near = 1;
            AspectRatio = 4/3f;
            FieldOfView = 3.14f/4f;
        }

        public override void Update()
        {
            base.Update();
            _camera.Position = Transform.WorldPosition;
            _camera.Up = Transform.Up;
            _camera.Forward = Transform.Forward;
        }
    }
}